/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.siagefi.controller;

import br.siagefi.model.NotaFiscal;
import br.siagefi.service.NotaFiscalService;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Paulo Lavarini
 */

@ManagedBean
@SessionScoped
public class NotaFiscalBean implements Serializable{
    
   private NotaFiscal notaFiscal;
   private final NotaFiscalService service;
   private List<NotaFiscal> notasFiscais;

    public NotaFiscalBean() {
        this.notaFiscal = new NotaFiscal();
        this.service = new NotaFiscalService();
        this.carregarLista();
    }
    
     public final void carregarLista(){
         this.notasFiscais = service.listar();
    }
    
    public String gravar(){
        service.gravar(this.getNotaFiscal());
        this.limparFormularioDoJsf();
        this.carregarLista();
        return "notaFiscal?faces-redirect=true";
    }
    
    public String alterar(NotaFiscal notaFiscal){
        this.setNotaFiscal(notaFiscal);
        return "incluirNotaFiscal";
    }
    
     public String remover(){
        service.remover(this.getNotaFiscal());
        this.limparFormularioDoJsf();
        this.carregarLista();
        return "notaFiscal";
    }
     
    public String remover(NotaFiscal notaFiscal){
        service.remover(notaFiscal);
        this.limparFormularioDoJsf();
        this.carregarLista();
        return "notaFiscal";
    }
  
    public void limparFormularioDoJsf(){
        this.notaFiscal = new NotaFiscal();
    }

    public NotaFiscal getNotaFiscal() {
        return notaFiscal;
    }

    public void setNotaFiscal(NotaFiscal notaFiscal) {
        this.notaFiscal = notaFiscal;
    }

    public List<NotaFiscal> getNotasFiscais() {
        return notasFiscais;
    }

    public void setNotaFiscals(List<NotaFiscal> notasFiscais) {
        this.notasFiscais = notasFiscais;
    }
    
    
}
